package com.mindbook.vip.gawxchatinfo.controller.user;

import cn.shuibo.annotation.Decrypt;
import com.mindbook.vip.gawxchatinfo.config.shiro.LoginTypeToken;
import com.mindbook.vip.gawxchatinfo.utils.RsaUtils;
import com.mindbook.vip.gawxchatinfo.utils.result.Result;
import com.mindbook.vip.gawxchatinfo.utils.result.ResultEnum;
import com.mindbook.vip.gawxchatinfo.utils.result.ResultUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.web.bind.annotation.*;

import java.security.GeneralSecurityException;

/**
 * @Author wxb
 * @Datatime 2022/4/6 12:24
 * @Descript 后端用户管理
 */

@RestController
@RequestMapping("back/user")
@Api(tags = "后台用户")
public class UserBackController {

    @Decrypt
    @CrossOrigin
    @PostMapping("/login")
    @ApiOperation(value = "后台管理用户认证")
    public Result backLogin(
            @ApiParam(name = "username",value = "账户",required = true) String username,
            @ApiParam(name = "password",value = "密码",required = true) String password) throws GeneralSecurityException {
        String passwordDecrypt = RsaUtils.decrypt(password);
        Subject subject = SecurityUtils.getSubject();
        subject.isAuthenticated();
        LoginTypeToken token = new LoginTypeToken(username,passwordDecrypt,"UserBackRealm");
        subject.login(token);
        return ResultUtils.genSuccessResult(ResultEnum.SHIRO_LOGIN_SUCCESS.getMsg());
    }

}
